CLASS zcl_po_test_001 DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.

    INTERFACES if_oo_adt_classrun .
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.



CLASS ZCL_PO_TEST_001 IMPLEMENTATION.


  METHOD if_oo_adt_classrun~main.

DATA:
  ls_business_data TYPE ztest_scm_po_wh=>tys_purchase_order_type,
  lo_http_client   TYPE REF TO if_web_http_client,
  lo_client_proxy  TYPE REF TO /iwbep/if_cp_client_proxy,
  lo_request       TYPE REF TO /iwbep/if_cp_request_create,
  lo_response      TYPE REF TO /iwbep/if_cp_response_create.


TRY.
" Create http client
*DATA(lo_destination) = cl_http_destination_provider=>create_by_comm_arrangement(
*                                             comm_scenario  = '<Comm Scenario>'
*                                             comm_system_id = '<Comm System Id>'
*                                             service_id     = '<Service Id>' ).
*lo_http_client = cl_web_http_client_manager=>create_by_http_destination( lo_destination ).
lo_client_proxy = /iwbep/cl_cp_factory_remote=>create_v4_remote_proxy(
  EXPORTING
     is_proxy_model_key       = VALUE #( repository_id       = 'DEFAULT'
                                         proxy_model_id      = 'ZTEST_SCM_PO_WH'
                                         proxy_model_version = '0001' )
    io_http_client             = lo_http_client
    iv_relative_service_root   = '<service_root>' ).

ASSERT lo_http_client IS BOUND.


* Prepare business data
ls_business_data = VALUE #(
          purchase_order              = 'PurchaseOrder'
          purchase_order_type_2       = 'PurchaseOrderType2'
          purchase_order_subtype      = 'PurchaseOrderSubtype'
          purchasing_document_origin  = 'PurchasingDocumentOrigin'
          purchasing_document_proces  = 'PurchasingDocumentProces'
          created_by_user             = 'CreatedByUser'
          creation_date               = '20170101'
          purchase_order_date         = '20170101'
          last_change_date_time       = 20170101123000
          validity_start_date         = '20170101'
          validity_end_date           = '20170101'
          language                    = 'Language'
          purchase_order_deletion_co  = 'PurchaseOrderDeletionCo'
          release_is_not_completed    = abap_true
          purchasing_completeness_st  = abap_true
          purchasing_processing_stat  = 'PurchasingProcessingStat'
          purg_release_sequence_stat  = 'PurgReleaseSequenceStat'
          release_code                = 'ReleaseCode'
          purchasing_release_strateg  = 'PurchasingReleaseStrateg'
          purg_reason_for_doc_cancel  = 'PurgReasonForDocCancel'
          company_code                = 'CompanyCode'
          purchasing_organization     = 'PurchasingOrganization'
          purchasing_group            = 'PurchasingGroup'
          supplier                    = 'Supplier'
          manual_supplier_address_id  = 'ManualSupplierAddressId'
          supplier_address_id         = 'SupplierAddressId'
          supplier_resp_sales_person  = 'SupplierRespSalesPerson'
          supplier_phone_number       = 'SupplierPhoneNumber'
          supplying_supplier          = 'SupplyingSupplier'
          supplying_plant             = 'SupplyingPlant'
          invoicing_party             = 'InvoicingParty'
          customer                    = 'Customer'
          purchase_contract           = 'PurchaseContract'
          supplier_quotation_externa  = 'SupplierQuotationExterna'
          quotation_submission_date   = '20170101'
          item_number_interval_for_s  = 'ItemNumberIntervalForS'
          payment_terms               = 'PaymentTerms'
          cash_discount_1_days        = '1'
          cash_discount_2_days        = '1'
          net_payment_days            = '1'
          cash_discount_1_percent     = '1'
          cash_discount_2_percent     = '1'
          down_payment_type           = 'DownPaymentType'
          down_payment_percentage_of  = '1'
          down_payment_amount         = 5550
          down_payment_due_date       = '20170101'
          incoterms_classification    = 'IncotermsClassification'
          incoterms_transfer_locatio  = 'IncotermsTransferLocatio'
          incoterms_version           = 'IncotermsVersion'
          incoterms_location_1        = 'IncotermsLocation1'
          incoterms_location_2        = 'IncotermsLocation2'
          is_intrastat_reporting_rel  = abap_true
          is_intrastat_reporting_exc  = abap_true
          correspnc_external_referen  = 'CorrespncExternalReferen'
          correspnc_internal_referen  = 'CorrespncInternalReferen'
          pricing_document            = 'PricingDocument'
          pricing_procedure           = 'PricingProcedure'
          document_currency           = 'DocumentCurrency'
          exchange_rate               = '1'
          exchange_rate_is_fixed      = abap_true
          tax_return_country          = 'TaxReturnCountry'
          vatregistration_country     = 'VatregistrationCountry'
          purg_aggrgd_prod_cmplnc_su  = 'PurgAggrgdProdCmplncSu'
          purg_aggrgd_prod_marketabi  = 'PurgAggrgdProdMarketabi'
          purg_aggrgd_sfty_data_shee  = 'PurgAggrgdSftyDataShee'
          purg_prod_cmplnc_tot_dngrs  = 'PurgProdCmplncTotDngrs'
          purchasing_collective_numb  = 'PurchasingCollectiveNumb' ).

" Navigate to the resource and create a request for the create operation
lo_request = lo_client_proxy->create_resource_for_entity_set( 'PURCHASE_ORDER' )->create_request_for_create( ).

" Set the business data for the created entity
lo_request->set_business_data( ls_business_data ).

" Execute the request
lo_response = lo_request->execute( ).

" Get the after image
*lo_response->get_business_data( IMPORTING es_business_data = ls_business_data ).

CATCH /iwbep/cx_cp_remote INTO DATA(lx_remote).
" Handle remote Exception
" It contains details about the problems of your http(s) connection


CATCH /iwbep/cx_gateway INTO DATA(lx_gateway).
" Handle Exception

CATCH cx_web_http_client_error INTO DATA(lx_web_http_client_error).
" Handle Exception
RAISE SHORTDUMP lx_web_http_client_error.

ENDTRY.
  ENDMETHOD.
ENDCLASS.
